package com.itheima.user.controller;

import com.itheima.common.entity.Result;
import com.itheima.pojo.Setmeal;
import com.itheima.user.service.SetmealService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RequestMapping("/setmeal")
@RestController
@Slf4j
public class SetMealController {
    @Autowired
    private SetmealService setmealService;

    /**
     * 查询所有套餐信息
     */
    @PostMapping("/getSetmeal")
    public Result getSetmeal() {
        try {
            List<Setmeal> setmeals = setmealService.findAll();
            return new Result(true, "查询套餐数据成功", setmeals);
        } catch (Exception e) {
            return new Result(false, "查询套餐数据失败");
        }
    }

    /**
     * 根据id查询套餐详情（套餐基本信息，套餐对应的检查组、检查组对应的检查项）
     */
    @PostMapping("/findById")
    public Result findById(@RequestParam Integer id){
        try {
            log.info("根据id查询套餐详情：{}",id);
            Setmeal setmeal = setmealService.findById(id);
            return new Result<>(true,"查询成功",setmeal);
        } catch (Exception e) {
            e.printStackTrace();
            return new Result(false,"查询失败");
        }

    }

}
